package com.czp.role.junit;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.czp.role.model.Role;

public class TestMapper {

	//private SqlSessionFactory sessionFactory;
	private static SqlSessionFactoryBuilder builder;
	private static SqlSessionFactory sessionFactory;
	static {
		builder = new SqlSessionFactoryBuilder();
		sessionFactory = builder.build(Thread.currentThread()
				.getContextClassLoader()
				.getResourceAsStream("mybatis.xml"));
	}
	
	
	public static void main(String[] args) {
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		TestMapper TestMapper = (TestMapper)ctx.getBean("TestMapper");
		TestMapper.getList();
	}
	
	@Test
	public void getList(){
		SqlSession sqlSession = sessionFactory.openSession();
		//TestEntity entity = new TestEntity();
		List<Role> roles = sqlSession.selectList("com.czp.role.mapper.IRoleMapper.getRoleList", Role.class, new RowBounds(0, 10));
		sqlSession.commit();
		sqlSession.close();
		for (Role role : roles) {
			System.out.println(role.toString());
		}
	}
	
	public SqlSessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SqlSessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}
